<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/13
 * Time: 15:49
 */

namespace app\api\controller;

use app\api\model\Xl AS XlModel;
use app\api\validate\IdMustPositiveInteger;

class Xl extends Base
{
    /**
     * 系列
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function xlList(){
        $XL = new XlModel();
        $where = [
            'device_type' => 1,
            'device_status' => 1
        ];
        $field = 'device_id, device_name';
        $_xl = $XL::selectXl($where, $field);
        if($_xl){
            return json(['status' => 200, 'msg' => $_xl]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }

    /**
     * 型号列表
     * id      系列ID
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function xhList(){
        $xl_id = input('id');

        $result = (new IdMustPositiveInteger())->goCheck();
        if($result['status'] == 0) return json(['status' => 0, 'msg' => $result['msg']]);

        $XH = new XlModel();
        $where = [
            'device_pid' => $xl_id,
            'device_status' => 1
        ];
        $field = 'device_id, device_name';
        $_xh = $XH::selectXl($where, $field);
        if($_xh){
            return json(['status' => 200, 'msg' => $_xh]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }

    }
}